package com.disapand.mall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.disapand.mall.annotation.CustomAnnotation;
import com.disapand.mall.util.FormatResponse;
import com.disapand.mall.entity.SmsCoupon;
import com.disapand.mall.service.impl.SmsCouponServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 优惠卷表 前端控制器
 * </p>
 *
 * @author author
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/sms-coupon")
@Api( value = "优惠券接口")
public class SmsCouponController {

    @Autowired
    private SmsCouponServiceImpl service;

    @ApiOperation(value = "根据 id 获取优惠券信息")
    @ApiImplicitParam(paramType = "param", name = "id", value = "优惠券id", required = true, dataType = "Integer")
    @GetMapping("/coupon/{id}")
    public FormatResponse getCoupon(@PathVariable Long id) {
        SmsCoupon coupon = service.getById(id);
        return FormatResponse.ofSuccess(coupon);
    }

    @CustomAnnotation("测试")
    @ApiOperation(value = "获取所有优惠券信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "param", name = "page", value = "页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "param", name = "pageSize", value = "每页的数量", required = false, dataType = "Integer")
    })
    @GetMapping("/coupons")
    public FormatResponse getCoupons(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {
        IPage<SmsCoupon> coupons = service.page(new Page<>(page, pageSize));
        return FormatResponse.ofSuccess(coupons);
    }

}
